{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane" lay-filter="user_form">
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('nickname')}</label>
            <div class="layui-input-4">
                <input type="text" name="nickname" ng-model="field.nickname" lay-verify="required" placeholder="{:lang('pleaseEnter')}{:lang('nickname')}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-4">
                <input type="text" name="realname" ng-model="field.realname" lay-verify="required" placeholder="输入真实姓名"
                    class="layui-input">
        </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('tel')}</label>
            <div class="layui-input-4">
                <input type="text" name="mobile" ng-model="field.mobile" disabled class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">{:lang('sex')}</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" ng-model="field.sex" ng-checked="field.sex==1" ng-value="1" title="{:lang('man')}">
                    <input type="radio" name="sex" ng-model="field.sex" ng-checked="field.sex==0" ng-value="0" title="{:lang('woman')}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户状态</label>
            <div class="layui-input-4">
                <select name="lock" id="">
                    <option value="0">启用</option>
                    <option value="1">禁用</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户类型</label>
            <div class="layui-input-4">
                <select name="user_type" lay-filter="user_type"  id="user_type">
                    {volist name="user_type" id="vo"}
                    <option value="{$key}">{$vo}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item" id="account_div">
            <label class="layui-form-label">账户余额</label>
            <div class="layui-input-4">
                <input type="text" name="account" ng-model="field.account" placeholder="输入账户余额" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" id="brand_div">
            <label class="layui-form-label">品牌加盟商</label>
            <div class="layui-input-block">
                {volist name="brand" id="vo"}
                <input type="checkbox" name="brand[{$vo.id}]" title="{$vo.title}" {if condition="in_array($vo.id, $agent)" } checked="checked" {/if}>
                {/volist}
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script src="/static/common/js/angular.min.js"></script>
<script>
    var m = angular.module('hd',[]);
    m.controller('ctrl',function($scope) {
        $scope.field = {$info|raw};
        layui.use(['form', 'layer'], function () {
            var form = layui.form, layer = layui.layer,$= layui.jquery;
            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                data.field.id = $scope.field.id;
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })

            //表单赋值
            form.val('user_form', {
                "user_type": $scope.field.user_type,
                "lock": $scope.field.lock,
            });

            form.on('select(user_type)', function (data) {
                //使用layui的form.on绑定select选中事件
                if (data.value == 3) {
                     $("#account_div").show()
                    $("#brand_div").show()
                } 
                else {
                    $("#account_div").hide()
                    $("#brand_div").hide()
                }
            });

            if($("#user_type").val() == 3){
                $("#account_div").show()
                $("#brand_div").show()
            }
            else{
                $("#account_div").hide()
                $("#brand_div").hide()
            }
        });
    });
</script>
</body>
</html>